package com.yylending.las.authority.password;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yylending.las.Global;
import com.yylending.las.common.AESEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by HenryZhang on 2016/11/21.
 * Copyright © 2016 www.yyfax.com. All Rights Reserved.
 */
public class ModifyPwdModel extends Model {

	private static final String TAG = "ModifyPwdModel";

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		return service.modifyPwd(Global.LOGIN_TOKEN, (AESEntity) params);
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		ModifyPwdResult result = cast(obj);
		EventAgent.post(result);
	}

	private interface Service {
		/**
		 * 修改密码
		 */
		@POST("server/cuser/setPassword")
		Observable<ModifyPwdResult> modifyPwd(@Header("token") String token, @Body AESEntity modifyPwd);
	}

	static class ModifyPwdResult extends BaseResultEntity<EmptyEntity> {
	}

	public static class ModifyPwd {
		public String password;
		public String newPassword;

		public ModifyPwd(String pwd, String newPwd) {
			password = pwd;
			newPassword = newPwd;
		}
	}
}
